package com.yf.course.modules.course.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yf.ability.log.annon.LogInject;
import com.yf.ability.log.enums.LogType;
import com.yf.base.api.annon.DataProtect;
import com.yf.base.api.api.ApiRest;
import com.yf.base.api.api.controller.BaseController;
import com.yf.base.api.api.dto.PagingReqDTO;
import com.yf.course.modules.course.dto.CourseDTO;
import com.yf.course.modules.course.dto.ext.CourseDetailExtDTO;
import com.yf.course.modules.course.dto.request.CourseSpeechReqDTO;
import com.yf.course.modules.course.entity.Course;
import com.yf.course.modules.course.entity.Speech;
import com.yf.course.modules.course.service.SpeechService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程讲稿控制器
 * </p>
 */
@Api(tags = {"课程讲稿"})
@RestController
@RequestMapping("/api/course/speech")
public class CourseSpeechController extends BaseController {
    @Autowired
    private SpeechService speechService;

    /**
     * 添加讲稿
     * @param courseSpeechReqDTO 请求参数
     */
    @ApiOperation(value = "添加或修改")
    @PostMapping("/save")
    public ApiRest save(@RequestBody CourseSpeechReqDTO courseSpeechReqDTO) {
        Boolean result = speechService.save(courseSpeechReqDTO);
        if (result) {
            return super.success();
        } else {
            return super.failure("添加或修改失败");
        }
    }

    /**
     * 删除讲稿
     * @param speechId 讲稿ID
     */
    @ApiOperation(value = "删除")
    @PostMapping("/delete")
    public ApiRest delete(@RequestParam(value = "speechId") String speechId) {
        Boolean result = speechService.delete(speechId);
        if (result) {
            return super.success("删除成功");
        } else {
            return super.failure("删除失败");
        }
    }

    /**
     * 根据Id获取讲稿
     * @param speechId 讲稿ID
     */
    @ApiOperation(value = "根据Id获取讲稿")
    @PostMapping("/selectById")
    public ApiRest<Speech> selectById(@RequestParam(value = "speechId") String speechId) {
        Speech speech = speechService.getById(speechId);
        if (speech == null) {
            return super.failure("没有找到该讲稿");
        }
        return super.success(speech);
    }

    /**
     * 分页获取讲稿
     * @param reqDTO 分页参数
     */
    @ApiOperation(value = "分页查找")
    @PostMapping("/paging")
    public ApiRest<IPage<Speech>> paging(@RequestBody PagingReqDTO<CourseSpeechReqDTO> reqDTO) {
        IPage<Speech> page = speechService.paging(reqDTO);
        return super.success(page);
    }
}
